package com.hmall.api.client;

import com.hmall.api.config.DefaultFeignConfig;
import com.hmall.api.domain.dto.ItemDTO;
import com.hmall.api.domain.dto.OrderDetailDTO;
import com.hmall.api.domain.dto.PageInfo;
import com.hmall.api.domain.dto.PageQueryDTO;
import com.hmall.api.fallback.ItemClientFactory;
import com.hmall.common.domain.PageDTO;
import com.hmall.common.domain.PageQuery;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

@FeignClient(value = "item-service",fallbackFactory = ItemClientFactory.class)
public interface ItemClient {
    /**
     * * GET http://[item-service]/items?ids=1,2,3
     */
    @GetMapping("/items")
    List<ItemDTO> queryItemByIds(@RequestParam("ids")Collection<Long> ids);

    @GetMapping("/items/{id}")
    ItemDTO queryItemById(@PathVariable("id") Long id);

    @PutMapping("/items/stock/deduct")
    void deductStock(@RequestBody List<OrderDetailDTO> items);

    @PostMapping("/items/stock/restore")
    void restoreStock(@RequestBody List<OrderDetailDTO> items);

    @GetMapping("/items/page")
    PageInfo<ItemDTO> queryItemByPage(@RequestParam PageQueryDTO query);

}


